import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.taotao.mapper.TbItemMapper;
import com.taotao.pojo.TbItem;
import com.taotao.pojo.TbItemExample;
import org.junit.Test;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.util.List;

/**
 * @author 康世行
 * @Title:
 * @Package PACKAGE_NAME
 * @Description: 测试类
 * @date 2021-07-31 15:57
 */
public class testt {
    @Test
    public void testPagehelper(){
       //1.获得mapper代理对象
        ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext("classpath:spring/applicationContext-*.xml");
        TbItemMapper tbItemMapper = applicationContext.getBean(TbItemMapper.class);
        //2.设置分页
        PageHelper.startPage(1,30);
        //3.执行查询
        TbItemExample example=new TbItemExample();
        List<TbItem> list = tbItemMapper.selectByExample(example);
        //4.取分页后结果
        PageInfo<TbItem> pageInfo = new PageInfo<>(list);
        long total = pageInfo.getTotal(); //总条数
        System.out.println("total:"+total);
        int pages = pageInfo.getPages(); //总页数
        System.out.println("pages:"+pages);
        int pageSize = pageInfo.getPageSize();
        System.out.println("pagesize:"+pageSize);

    }
}
